f65925
@@ -205,21 +205,27 @@
private void mergeMapJoinTaskWithChildMapJoinTask(MapRedTask task, Configuration
       }
     }
 
+    // Merge the 2 trees - remove the FileSinkOperator from the first tree pass it to the
+    // top of the second
     Operator<? extends Serializable> childAliasOp =
         childWork.getAliasToWork().values().iterator().next();
     if (fop.getParentOperators().size() > 1) {
       return;
     }
-
-    // Merge the 2 trees - remove the FileSinkOperator from the first tree pass it to the
-    // top of the second
     Operator<? extends Serializable> parentFOp = fop.getParentOperators().get(0);
-    parentFOp.getChildOperators().remove(fop);
-    parentFOp.getChildOperators().add(childAliasOp);
-    List<Operator<? extends OperatorDesc>> parentOps =
-        new ArrayList<Operator<? extends OperatorDesc>>();
-    parentOps.add(parentFOp);
-    childAliasOp.setParentOperators(parentOps);
+    // remove the unnecessary TableScan
+    if (childAliasOp instanceof TableScanOperator) {
+      TableScanOperator tso = (TableScanOperator)childAliasOp;
+      if (tso.getNumChild() != 1) {
+        // shouldn't happen
+        return;
+      }
+      childAliasOp = tso.getChildOperators().get(0);
+      childAliasOp.replaceParent(tso, parentFOp);
+    } else {
+      childAliasOp.setParentOperators(Utilities.makeList(parentFOp));
+    }
+    parentFOp.replaceChild(fop, childAliasOp);
 
     work.getAliasToPartnInfo().putAll(childWork.getAliasToPartnInfo());
     for (Map.Entry<String, PartitionDesc> childWorkEntry : childWork.getPathToPartitionInfo()
